package com.xxxx.ssm.controller;

import com.xxxx.ssm.po.User;
import com.xxxx.ssm.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * 现在做一个登录操作
 * 登录 成功  之后返回到登录成功的页面
 * 使用拦截器进行拦截判断
 */
@Controller
public class UserController {

    @Resource
    private UserService userService;

    /**
     *
     * @return
     */
    @RequestMapping("/login_page")
    public ModelAndView login_page(){
        ModelAndView modelAndView =  new ModelAndView();
        modelAndView.setViewName("login_page");
        return modelAndView;
    }


    /**
     * 用户登录
     * @param userParam
     * @return
     */
    @RequestMapping("/user_login")
    @ResponseBody
    public User user_login(User userParam , HttpSession session){
        System.out.println(userParam);
        User user = userService.userLoginByUserInfo(userParam);
        session.setAttribute("user" , user);
        System.out.println(user);
        return user;
    }


    @RequestMapping("/login_success")
    public ModelAndView login_success(){
        ModelAndView modelAndView =  new ModelAndView();
        modelAndView.setViewName("login_success");
        return modelAndView;
    }



}
